package o;

import androidx.annotation.Nullable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public final class amj implements amh {
    public static final amj ˎ = new amj(Collections.emptyMap());
    private final Map<String, byte[]> ˊ;
    private int ˋ;

    public static amj ˎ(DataInputStream dataInputStream) throws IOException {
        int readInt = dataInputStream.readInt();
        Map hashMap = new HashMap();
        for (int i = 0; i < readInt; i++) {
            String readUTF = dataInputStream.readUTF();
            int readInt2 = dataInputStream.readInt();
            if (readInt2 < 0 || readInt2 > 10485760) {
                throw new IOException("Invalid value size: " + readInt2);
            }
            Object obj = new byte[readInt2];
            dataInputStream.readFully(obj);
            hashMap.put(readUTF, obj);
        }
        return new amj(hashMap);
    }

    private amj(Map<String, byte[]> map) {
        this.ˊ = Collections.unmodifiableMap(map);
    }

    public amj ˊ(ami o_ami) {
        Map ˊ = ˊ(this.ˊ, o_ami);
        if (ˎ(ˊ)) {
            return this;
        }
        this(ˊ);
        return this;
    }

    public void ˏ(DataOutputStream dataOutputStream) throws IOException {
        dataOutputStream.writeInt(this.ˊ.size());
        for (Entry entry : this.ˊ.entrySet()) {
            dataOutputStream.writeUTF((String) entry.getKey());
            byte[] bArr = (byte[]) entry.getValue();
            dataOutputStream.writeInt(bArr.length);
            dataOutputStream.write(bArr);
        }
    }

    public final String ˊ(String str, String str2) {
        if (this.ˊ.containsKey(str)) {
            return new String((byte[]) this.ˊ.get(str), Charset.forName("UTF-8"));
        }
        return str2;
    }

    public final long ॱ(String str, long j) {
        if (this.ˊ.containsKey(str)) {
            return ByteBuffer.wrap((byte[]) this.ˊ.get(str)).getLong();
        }
        return j;
    }

    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        return ˎ(((amj) obj).ˊ);
    }

    private boolean ˎ(Map<String, byte[]> map) {
        if (this.ˊ.size() != map.size()) {
            return false;
        }
        for (Entry entry : this.ˊ.entrySet()) {
            if (!Arrays.equals((byte[]) entry.getValue(), (byte[]) map.get(entry.getKey()))) {
                return false;
            }
        }
        return true;
    }

    public int hashCode() {
        if (this.ˋ == 0) {
            int i = 0;
            for (Entry entry : this.ˊ.entrySet()) {
                i = (Arrays.hashCode((byte[]) entry.getValue()) ^ ((String) entry.getKey()).hashCode()) + i;
            }
            this.ˋ = i;
        }
        return this.ˋ;
    }

    private static Map<String, byte[]> ˊ(Map<String, byte[]> map, ami o_ami) {
        HashMap hashMap = new HashMap(map);
        ॱ(hashMap, o_ami.ˎ());
        ˎ(hashMap, o_ami.ˋ());
        return hashMap;
    }

    private static void ॱ(HashMap<String, byte[]> hashMap, List<String> list) {
        for (int i = 0; i < list.size(); i++) {
            hashMap.remove(list.get(i));
        }
    }

    private static void ˎ(HashMap<String, byte[]> hashMap, Map<String, Object> map) {
        for (String str : map.keySet()) {
            Object ˏ = ˏ(map.get(str));
            if (ˏ.length > 10485760) {
                throw new IllegalArgumentException("The size of " + str + " (" + ˏ.length + ") is greater than maximum allowed: " + 10485760);
            }
            hashMap.put(str, ˏ);
        }
    }

    private static byte[] ˏ(Object obj) {
        if (obj instanceof Long) {
            return ByteBuffer.allocate(8).putLong(((Long) obj).longValue()).array();
        }
        if (obj instanceof String) {
            return ((String) obj).getBytes(Charset.forName("UTF-8"));
        }
        if (obj instanceof byte[]) {
            return (byte[]) obj;
        }
        throw new IllegalArgumentException();
    }
}
